package com.vm.osm.business.service.impl;

import com.vm.osm.business.dao.OsmCheckPlanInstMapper;
import com.vm.osm.business.dao.OsmOrderEvaluateMapper;
import com.vm.osm.business.dao.OsmOrderFailureMapper;
import com.vm.osm.business.dto.req.evaluate.ReqEvaluate;
import com.vm.osm.business.entity.OsmCheckPlanInst;
import com.vm.osm.business.entity.OsmOrderEvaluate;
import com.vm.osm.business.entity.OsmOrderFailure;
import com.vm.osm.business.service.IOsmOrderEvaluateService;
import com.vm.osm.business.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Created by chenzui on 2018/4/30.
 */
@Service
public class OsmOrderEvaluateServiceImpl implements IOsmOrderEvaluateService {
    @Autowired
    private OsmOrderEvaluateMapper osmOrderEvaluateMapper;

    @Autowired
    private OsmOrderFailureMapper osmOrderFailureMapper;

    @Autowired
    private OsmCheckPlanInstMapper osmCheckPlanInstMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return osmOrderEvaluateMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(OsmOrderEvaluate record) {
        return osmOrderEvaluateMapper.insert(record);
    }

    @Override
    public int insertSelective(OsmOrderEvaluate record) {
        return osmOrderEvaluateMapper.insertSelective(record);
    }

    @Override
    public OsmOrderEvaluate selectByPrimaryKey(String id) {
        return osmOrderEvaluateMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(OsmOrderEvaluate record) {
        return osmOrderEvaluateMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(OsmOrderEvaluate record) {
        return osmOrderEvaluateMapper.updateByPrimaryKey(record);
    }

    @Override
    public void evaluate(ReqEvaluate reqEvaluate, HttpServletRequest request) {
        String type = reqEvaluate.getType();
        String orderId = reqEvaluate.getOrder_id();

        OsmOrderEvaluate evaluate = new OsmOrderEvaluate();
        evaluate.setOrderId(orderId);
        evaluate.setLabelCode(reqEvaluate.getLabel_code());
        evaluate.setExtInfo(reqEvaluate.getExt_info());
        evaluate.setStarCode(reqEvaluate.getStar_code());
        evaluate.setCreateTime(new Date());
        evaluate.setId(UuidUtil.getRandomUuid());
        evaluate.setUpdateTime(new Date());
        if(type.equals("1")){
            OsmOrderFailure order = osmOrderFailureMapper.selectByPrimaryKey(orderId);
            order.setStatus("15");
            osmOrderFailureMapper.updateByPrimaryKeySelective(order);

        }else if(type.equals("2")){
            OsmCheckPlanInst order = osmCheckPlanInstMapper.selectByPrimaryKey(orderId);
            order.setStatus("15");
            osmCheckPlanInstMapper.updateByPrimaryKeySelective(order);
        }
    }
}
